#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Author    : g1879
# @date      : 2020/12/9
# @email     : g1879@qq.com
# @File      : 爬链家3.py
from time import sleep
from DrissionPage import MixPage

url = 'https://sz.lianjia.com/ershoufang/luohuqu/pg{}/'

p = MixPage('s')
p.get(url.format(1))
page_data = p('.page-box house-lst-page-box').attr('page-data')
pages_count = eval(page_data)['totalPage']

all_data = []
print('\n第1页')

for page in range(2, pages_count + 1):
    for row in p.eles('xpath://ul[@class="sellListContent"]/li'):
        link = row('xpath://div[@class="title"]/a')
        info = row('xpath://div[@class="houseInfo"]')
        page_data = [link.text, link.link, info.text]

        all_data.append(page_data)
        print(page_data)

    sleep(1)
    p.get(url.format(page))
    print(f'\n第{page}页')
